package adminAction;

import dao.UserDao;
import po.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/admin/adminAction/AdminLoginServlet")
public class AdminLoginServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String adminName = req.getParameter("adminName");
        String pwd = req.getParameter("adminPwd");
        UserDao userDao = new UserDao();
        User user = new User();
        user.setUname(adminName);
        user.setUpwd(pwd);
        user.setRole(1);
        User admin = userDao.selectByUnamePasswordAndRole(user);
        String url = "../page/login.html";
        if (admin!=null){
            req.getSession().setAttribute("admin",admin);
            url = "../page/index.jsp";
        }
        req.getRequestDispatcher(url).forward(req,resp);
    }
}
